package chess;

import java.awt.Point;
import java.util.ArrayList;

public abstract class LineMover extends Piece{
	
	protected ArrayList<Point> moveStyle;
	public static final Point NORTH = new Point(1,0);
	public static final Point NORTHEAST = new Point(1,1);
	public static final Point EAST = new Point(0,1);
	public static final Point SOUTHEAST = new Point(-1,1);
	public static final Point SOUTH = new Point(-1,0);
	public static final Point SOUTHWEST = new Point(-1,-1);
	public static final Point WEST = new Point(0,-1);
	public static final Point NORTHWEST = new Point(1,-1);
	
	
	/**
	 * Andrew Jeffery
	 * -created Class(Feb 22,2010)
	 *-Created Constructor(02/22/10)
	 *Refactored Queen Bishop and rook to use Linemover
	 *Changed 8 directional finds, to a general find and uses move styles and a array of directions
	 */

	public LineMover(Player p, Tile t) {
		super(p, t);
		this.moveStyle= new ArrayList<Point>();
		}
	
	/**
	 * This class was created to re use the code that defines the movement of Queen Rook and Bishop
	 * getMovementTiles makes use of a recursive helper function to the tiles in any one direction, then executes the helper function for each direction define by Movementstlye
	 * <pre>
	 * Andrew Jeffery
	 * -Creation (Feb 22,2010)
	 * </pre>
	 */	
	
	
	public ArrayList<Tile> getMovementTiles(){
		this.movementTiles.clear();
		for(Point direction :this.moveStyle){
			getMoveTileHelper(this.currentTile, direction);
		}
		return this.movementTiles;
	}
	
	/**
	 * The recursive finder for getting movement tiles, it ensures that we stay on the board when finding tiles
	 * <pre>
	 * Andrew Jeffery
	 * -Creation (Feb 22,2010)
	 * </pre>
	 */	
	

	private void getMoveTileHelper(Tile tile, Point heading){
		if ( ( (tile.getY()+(int)heading.getY() )>=0 ) && ( ( tile.getY() + (int)heading.getY() )<= 7 ) ){ 
				if ( (tile.getX()+(int)heading.getX() )>=0 && (tile.getX() + (int)heading.getX() )<=7 ) { //Test for all bounds on the Board
					Tile found=( tile.getBoard().getTile( tile.getX() + (int)heading.getX() , tile.getY() + (int)heading.getY() ) ); //Find the next tile based on the current heading
					this.movementTiles.add(found);
					if (!found.isPieceHere()){	//returns only one tile that contains a piece, then returns
						getMoveTileHelper(found, heading);
					}
				}
		}
		else{
			return;
		}
	}

}
